package sky.teleport_bow.listenners;

import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import sky.teleport_bow.Teleport_Bow;

public class BowListener implements Listener {

    private static final String TELEPORT_BOW = ChatColor.GREEN + "" + ChatColor.BOLD + "传送弓";

    @EventHandler
    public void onBowShoot(ProjectileHitEvent event) {
        if (event.getEntity().getType() == EntityType.ARROW) {
            if (event.getEntity().getShooter() instanceof Player p) {
                ItemStack itemInMainHand = p.getInventory().getItemInMainHand();

                if (itemInMainHand.getItemMeta().getDisplayName().equals(TELEPORT_BOW)) {
                    Location loc = event.getEntity().getLocation();
                    p.teleport(loc);
                    event.getEntity().remove();
                    p.sendMessage(ChatColor.BLUE + "传送成功");

                }
            }
        }
    }
}
